using GGameFramework.Event;

namespace GGameFramework.Runtime
{
    public class EventComponent : FrameworkComponent
    {
        EventManager mEventManager;

        public override FrameworkComponentPriority Priority => FrameworkComponentPriority.System;

        protected override void Awake()
        {
            base.Awake();

            mEventManager = FrameworkEntry.GetModule<EventManager>();
        }

        #region TypeEvent

        public void Register<EventBase>(System.Action<EventBase> onEvent)
        {
            mEventManager.Register(onEvent);
        }

        public void UnRegister(System.Action<EventBase> onEvent)
        {
            mEventManager.UnRegister(onEvent);
        }

        /// <summary>
        /// 无参事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void Send<T>() where T : EventBase, new()
        {
            mEventManager.Send<T>();
        }

        /// <summary>
        /// 有参事件
        /// </summary>
        /// <param name="eventData"></param>
        /// <typeparam name="T"></typeparam>
        public void Send<T>(T eventData) where T : EventBase, new()
        {
            mEventManager.Send(eventData);
        }

        #endregion
    }
}